package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-21 01:11
 */
public class NumDecodings {
    public int numDecodings(String s) {

        char[] chars = s.toCharArray();
        int[] dp = new int[chars.length + 1];
        dp[0] = 1;
        for (int i = 1; i < dp.length; i++) {
            if (chars[i-1]!='0'){
                dp[i]+=dp[i-1];
            }
            if (i>1&&chars[i-2]!='0'&&((chars[i-2]-'0')*10+chars[i-1]-'0')<=26){
                dp[i]+=dp[i-2];
            }
        }
        return dp[chars.length];
    }
}
